<?php
/**
 * 
 * Modelo de estatus control interno
 * @author Natanael
 * 
 */
class Mciestatus extends Model{

      private $_nameTable = "CI_estatus";
      
      public function __construct()
      {
      	 parent::Model();
         $this->load->database(); 
      }
      
      public function loadEstatus($start = false, $offset = false, $sortname = false, $sortorder = false)
      {
         if($offset != false)
		      $this->db->limit($offset, $start);
  
		 if($sortname != false && $sortorder != false){ 
				  $this->db->order_by($sortname, $sortorder);
		  }else{
			    $this->db->order_by('ID', 'ASC');
	     }	  
				  
		  $result = $this->db->get_where($this->_nameTable);
	
		   return $this->GetArrayFromQueryResult($result);
			
      }
         
       public function LoadStatusById($idStatus) 
	   {
		   $qresult = $this->db->get_where($this->_nameTable, array('ID' => $idStatus));		
		
		   if ($qresult->num_rows() == 0)
		   {
			 return false;
		   }	
           
		   return new CI_estatus($qresult->row());
	    }
         
         public function GetArrayFromQueryResult($result) 
	     {
			if ($result->num_rows() == 0)
				return false;
	
			$estatus_arr = array();
	
			foreach ($result->result() as $record) {
				$estatus_arr[] = new CI_estatus($record);
			}
	
			return $estatus_arr;
         }
         
        public function crear($data)
        {
           if ($this->db->insert($this->_nameTable,$data)) {
           	  return true;
           }
           
            return false;
        }
        
        public function edit($data, $id)
        {
           if ($this->db->update($this->_nameTable,$data,array('ID'=>$id))) {
           	  return true;
           }
           
            return false;
        }
        
        public function delete($id)
        {
             if ($this->db->delete($this->_nameTable,array('ID'=>$id))) {
           	    return true;
             }
           
              return false;
        }

}

class CI_estatus{
          
	     private $_id = 0;
	     private $_descripcion = "";
	    
	     
	     public function __construct($ojt)
	     {
	        $this->setIdStatus($ojt->ID);
	        $this->setDescripcion($ojt->Descripcion);
	        
	     } 
	     
	     public function getIdStatus(){
	        return $this->_id;
	     }
	     
         public function setIdStatus($ojt){
	        $this->_id = $ojt;
	     }
	     
	     public function getDescripcion()
	     {
	        return $this->_descripcion;
	     }
	     
         public function setDescripcion($ojt)
	     {
	        $this->_descripcion = $ojt;
	     }
	     
}